<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ include file="/pages/jsp/internal/include.jsp" %>

<div class="inner_cont">

<h2><fmt:message key="label.contentNew"/></h2>

	<span class="note">
		
		<fmt:message key="page.newContent.description"/>
		
		<c:forEach items="${model.messages}" var="message">
		   	<div id="message"><fmt:message key="${message}"/></div>
		</c:forEach>
		
		<c:forEach items="${model.errors}" var="error">
		   	<div id="error">
		   		<fmt:message key="${error.key}">
		   			<fmt:param value="${error.param1}"/>
		   		</fmt:message>
		   	</div>
		</c:forEach>
	</span>
	<br/>
	
	<form id="contentForm" class="form" method="post" action="<c:url value="/content/newContent.htm"/>">
		
		<table class="tableForm" cellspacing="0" cellpadding="0" summary="0">
		
			<tr>
				<th scope="row" width="20%">Tipo contenuto * :</td>
				<td>
					<select name="fk_tipo_cont" id="fk_tipo_cont" >
						<c:forEach items="${model.contentTypes}" var="contentType" varStatus="i">
							<c:if test="${model.content.fk_tipo_cont == contentType.id}"> </c:if>
							
							<option value="<c:out value="${contentType.id}"/>"    
								<c:if test="${model.content.fk_tipo_cont == contentType.id}"><c:set var="descTipoContent" value="${contentType.descrizione}"/>selected </c:if>
							>
								<c:out value="${contentType.descrizione}"/>
							</option>
						</c:forEach>
					</select>
					
					<div id="skinsSelect" style="display:none;" >
						<select name="fk_tipo_skin" id="fk_tipo_skin">
							<c:forEach items="${model.contentSkins}" var="obj" varStatus="i">
								
								<option value="<c:out value="${obj.id}"/>"   tipo_cont="<c:out value="${obj.idContentType}"/>" url_preview="<c:url value="${obj.urlPreview}"/>"  
									<c:if test="${model.content.fk_tipo_skin == obj.id}">selected</c:if>
								>
									<c:out value="${obj.urlPreview}"/> , <c:out value="${obj.urlProd}"/>
								</option>
							</c:forEach>
						</select>
						
						<span id="viewTemplate">
							view template
						</span>
						
					</div>
					
					
				</td>
			</tr>
			<tr>
				<th scope="row"  width="20%">Titolo * :</td>
				<td><input type="text" name="titolo" value="<c:out value="${model.content.titolo}" />"/></td>
			</tr>
			<tr>
				<th scope="row"  width="20%">Strillo * :</td>
				<td><input type="text" name="strillo" value="<c:out value="${model.content.strillo}" />"/></td>
			</tr>
			<tr>
				<th scope="row"  width="20%">Descrizione * :</td>
				<td>
					<textarea name="descrizione" id="descrizione"><c:out value="${model.content.descrizione}" /></textarea>
				</td>
			</tr>
			<tr>
				<th scope="row"  width="20%">Data inizio :</td>
				<td> <input type="text" name="startDate" id="startDate" value="<fmt:formatDate pattern="dd/MM/yyyy" value="${model.content.startDate}"/>"/></td>
			</tr>
			<tr>
				<th scope="row"  width="20%">Data fine :</td>
				<td> <input type="text" name="endDate"  id="endDate" value="<fmt:formatDate pattern="dd/MM/yyyy" value="${model.content.endDate}"/>"/> </td>
			</tr>
			
			<tr>
				<th scope="row"  width="20%">Data inserimento :</td>
				<td> <input type="text" name="insDate"  id="insDate" value="<fmt:formatDate pattern="dd/MM/yyyy" value="${model.content.insDate}"/>"/> </td>
			</tr>
		</table>
	 	<br>
	 	<div class="action_bar">	
	 		<input type="button" class="puls"  value="Salva" onclick="sendForm('<c:url value="/content/newContent.htm"/>',$('#contentForm').serialize(),'body');"/>
		</div>
	</form>

</div>
<script type="text/javascript">
$(document).ready(function() {
	
	//Rimuovo l'istanza dell'editor se esiste e poi la ricreo
	/*var instance = CKEDITOR.instances['descrizione'];
    if(instance)
    {
        CKEDITOR.remove(instance);
    }
	  
	CKEDITOR.replace( 'descrizione',
	{
		fullPage : true
		//, extraPlugins : 'docprops'
	});
	
	$("#contentForm").submit(function() {
		//alert("beccato submit");
		sendForm('<c:url value="/content/newContent.htm"/>',$("#contentForm").serialize(),'body');
		//sendFormForAction('<c:url value="/content/newContent.htm"/>','contentForm','body','insert');
		return false;
	});*/
	var config = {
		extraPlugins : 'devtools'
		/*toolbar:[
			['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],
			['UIColor']
		]*/
	};
	
	var instance = CKEDITOR.instances['descrizione'];
	
    if(instance)
    {
        CKEDITOR.remove(instance);
    }
    
    //instance = $('#descrizione');
	
	
    instance =	$('#descrizione').ckeditor( 
		function() {
			var editor 	= $('#descrizione').ckeditorGet();
			var data 	= $('#descrizione').val();
			
		},
		config
	);
	
	$("#hasPrivate").change(function(){
		if($("#hasPrivate").is(":checked")) show('hasPrivateDiv');
		else hide('hasPrivateDiv');
	});
	
	
	$( "#startDate" ).datepicker({ 
		dateFormat : "dd/mm/yy",
		changeMonth: true,
		changeYear: true
	});
	$( "#endDate" ).datepicker({
		dateFormat : "dd/mm/yy",
		changeMonth: true,
		changeYear: true
	});
	$( "#insDate" ).datepicker({
		dateFormat : "dd/mm/yy",
		changeMonth: true,
		changeYear: true
	});

	function show(div){
		call('<c:url value="/content/userList.htm"><c:param name="contentId" value="${model.content.id}"/></c:url>',div);
		$('#'+div).show();
	};
	
	function hide(div){
		$('#'+div).hide();
	};
	
	
	
	onChangeTemp();
	
	
	
});
</script>

	